package com.lmm.lcbusiness.lcbusiness.pages.rnpages.plugins;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.WritableMap;
import com.lmm.dresswisdom.lmmframe.reactnative.BasePlugin;
import com.lmm.dresswisdom.lmmframe.reactnative.annotation.RNPlugin;
import com.lmm.lcbusiness.lcbusiness.config.AppInfoAction;
import com.lmm.lcbusiness.lcbusiness.config.AppKey;
import com.lmm.lcbusiness.lcbusiness.config.AppKeyValueUtils;
import com.lmm.lcbusiness.lcbusiness.pages.rnpages.ReactNativeActivity;

import java.util.Map;

/**
 * Created by xmgong on 2017/12/4.
 */
@RNPlugin(method = "logout")
public class LogoutPlugin extends BasePlugin<ReactNativeActivity> {
    public LogoutPlugin(ReactNativeActivity act) {
        super(act);
    }

    @Override
    protected void doAction(Map<String, Object> map, Callback callback) {
        //loginstate
        if (AppInfoAction.isLogin()) {
            AppKeyValueUtils.setValue(AppKey.LoginState, "0");
        }
        AppKeyValueUtils.setValue(AppKey.Token, "");
        AppKeyValueUtils.setValue(AppKey.ShopAddress, "");
        AppKeyValueUtils.setValue(AppKey.ShopLogo, "");
        AppKeyValueUtils.setValue(AppKey.ShopName, "");
        AppKeyValueUtils.setValue(AppKey.ShopToken, "");
        WritableMap res = Arguments.createMap();
        res.putString("loginstate", "0");
        callback.invoke(res);
    }
}
